package cn.com.zsc.schedule;

import java.util.Date;

import org.quartz.CronTrigger;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.impl.calendar.BaseCalendar;

import cn.com.zsc.properties.ReadProperties;

public class InitTask {
	
	public void addADTask(Scheduler schedulers){
		try{
			JobDetail jobDetail=new JobDetail("AD","AD",ScheduleJob.class);
			jobDetail.setRequestsRecovery(true);
			ReadProperties rp=new ReadProperties();
			String cron=rp.getValue("quartz.ad.autocron");
			CronTrigger trigger=new CronTrigger("adTrigger","AD",cron);
			BaseCalendar c=new BaseCalendar();
			Date firstDate=trigger.computeFirstFireTime(c.getBaseCalendar());
			Date factDate=new Date();
			System.out.println(factDate);
			if(firstDate.compareTo(factDate)>0)
				trigger.setStartTime(firstDate);
			else
				trigger.setStartTime(factDate);
			jobDetail.getJobDataMap().put("TASKID", "001");
			cn.com.zsc.schedule.SchedulerUtils.AddJob(jobDetail, trigger);
			
			System.out.println(">>>>>>>>>>>>>Init AD ETL finish,time is:"+trigger.getStartTime());
		}catch(Exception ex){
			ex.printStackTrace();
		}
	}
}
